package rhc.discribute.node.connecter.impl.zookper.watchCallback;

import java.util.Map;
import java.util.concurrent.CountDownLatch;

import org.apache.zookeeper.WatchedEvent;

import rhc.discribute.BaseComponent;
import rhc.discribute.node.connecter.impl.ZKPathLockData;
import rhc.discribute.node.connecter.impl.zookper.WatchCallback;
import rhc.discribute.node.connecter.impl.zookper.ZookperLockImpl;
import rhc.discribute.node.exception.CallbackException;

public class LockPathWatchCallback extends BaseComponent implements WatchCallback{

	public String ZK_LOCK="zkLock";
	
	public String LATCH="latch";
	
	public String ZK_PLD="zkPLD";
	
	@Override
	public void executeCallback(WatchedEvent event, Object callbackData) throws CallbackException {
		Map<String,Object> dataMap=(Map<String, Object>) callbackData;
		
		ZookperLockImpl zkLock=(ZookperLockImpl) dataMap.get(ZK_LOCK);
		CountDownLatch latch=(CountDownLatch) dataMap.get(LATCH);
		ZKPathLockData zkPLD=(ZKPathLockData) dataMap.get(ZK_PLD);
		
		try{
			zkLock.getLock(zkPLD, latch);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			dataMap.clear();
		}
		
	}

	@Override
	public boolean isSync() {
		return false;
	}

}
